Bug 540861 - invalid UTF-8 in input device name
authorTor Lillqvist <tml@novell.com>
Thu, 3 Jul 2008 22:11:38 +0000 (22:11 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Thu, 3 Jul 2008 22:11:38 +0000 (22:11 +0000)
2008-07-04  Tor Lillqvist  <tml@novell.com>

Bug 540861 - invalid UTF-8 in input device name

* gdk/win32/gdkinput-win32.c: Fetch the device and cursor names in
Unicode, and convert to UTF-8 for the GdkDevice's name field.

svn path=/trunk/; revision=20750

ChangeLog
gdk/win32/gdkinput-win32.c

index 80289f9999a5bbb8d86585321846c5a2cdf3c92b..997a173a4e3481370a8392286ae74bad41fe67f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-07-04  Tor Lillqvist  <tml@novell.com>
+
+       Bug 540861 - invalid UTF-8 in input device name
+
+       * gdk/win32/gdkinput-win32.c: Fetch the device and cursor names in
+       Unicode, and convert to UTF-8 for the GdkDevice's name field.
+
 2008-07-03  Matthias Clasen  <mclasen@redhat.com>
 
        Bug 540915 – GtkBuilder sets properties in reverse order
index 619a1c25815703a93e544b2a3267decec34f2c13..d844a5832f0767fce5eb3b34efefca4b869464fc 100644 (file)
@@ -63,6 +63,7 @@ static GdkEventMask x_grab_mask;
 static gboolean x_grab_owner_events;
 
 typedef UINT (WINAPI *t_WTInfoA) (UINT a, UINT b, LPVOID c);
+typedef UINT (WINAPI *t_WTInfoW) (UINT a, UINT b, LPVOID c);
 typedef BOOL (WINAPI *t_WTEnable) (HCTX a, BOOL b);
 typedef HCTX (WINAPI *t_WTOpenA) (HWND a, LPLOGCONTEXTA b, BOOL c);
 typedef BOOL (WINAPI *t_WTOverlap) (HCTX a, BOOL b);
@@ -70,6 +71,7 @@ typedef BOOL (WINAPI *t_WTPacket) (HCTX a, UINT b, LPVOID c);
 typedef int (WINAPI *t_WTQueueSizeSet) (HCTX a, int b);
 
 static t_WTInfoA p_WTInfoA;
+static t_WTInfoW p_WTInfoW;
 static t_WTEnable p_WTEnable;
 static t_WTOpenA p_WTOpenA;
 static t_WTOverlap p_WTOverlap;
@@ -334,7 +336,8 @@ _gdk_input_wintab_init_check (void)
   AXIS axis_x, axis_y, axis_npressure, axis_or[3];
   int i, k;
   int devix, cursorix;
-  char devname[100], csrname[100];
+  wchar_t devname[100], csrname[100];
+  gchar *devname_utf8, *csrname_utf8;
   BOOL defcontext_done;
   HMODULE wintab32;
 
@@ -353,6 +356,8 @@ _gdk_input_wintab_init_check (void)
 
   if ((p_WTInfoA = (t_WTInfoA) GetProcAddress (wintab32, "WTInfoA")) == NULL)
     return;
+  if ((p_WTInfoW = (t_WTInfoW) GetProcAddress (wintab32, "WTInfoW")) == NULL)
+    return;
   if ((p_WTEnable = (t_WTEnable) GetProcAddress (wintab32, "WTEnable")) == NULL)
     return;
   if ((p_WTOpenA = (t_WTOpenA) GetProcAddress (wintab32, "WTOpenA")) == NULL)
@@ -395,13 +400,17 @@ _gdk_input_wintab_init_check (void)
     {
       LOGCONTEXT lc;
       
-      /* We open the Wintab device (hmm, what if there are several?) as a
-       * system pointing device, i.e. it controls the normal Windows
+      /* We open the Wintab device (hmm, what if there are several, or
+       * can there even be several, probably not?) as a system
+       * pointing device, i.e. it controls the normal Windows
        * cursor. This seems much more natural.
        */
 
-      (*p_WTInfoA) (WTI_DEVICES + devix, DVC_NAME, devname);
-      
+      (*p_WTInfoW) (WTI_DEVICES + devix, DVC_NAME, devname);
+      devname_utf8 = g_utf16_to_utf8 (devname, -1, NULL, NULL, NULL);
+#ifdef DEBUG_WINTAB
+      GDK_NOTE (INPUT, (g_print("Device %d: %s\n", devix, devname_utf8)));
+#endif
       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_NCSRTYPES, &ncsrtypes);
       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_FIRSTCSR, &firstcsr);
       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_HARDWARE, &hardware);
@@ -484,7 +493,7 @@ _gdk_input_wintab_init_check (void)
       for (cursorix = firstcsr; cursorix < firstcsr + ncsrtypes; cursorix++)
        {
 #ifdef DEBUG_WINTAB
-             GDK_NOTE (INPUT, (g_print("Cursor %d:\n", cursorix), print_cursor (cursorix)));
+         GDK_NOTE (INPUT, (g_print("Cursor %d:\n", cursorix), print_cursor (cursorix)));
 #endif
          active = FALSE;
          (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_ACTIVE, &active);
@@ -500,12 +509,14 @@ _gdk_input_wintab_init_check (void)
           * at least for Wacom, skip cursors with physid zero.
           */
          (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PHYSID, &physid);
-         if (strcmp (devname, "WACOM Tablet") == 0 && physid == 0)
+         if (wcscmp (devname, L"WACOM Tablet") == 0 && physid == 0)
            continue;
 
          gdkdev = g_object_new (GDK_TYPE_DEVICE, NULL);
-         (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_NAME, csrname);
-         gdkdev->info.name = g_strconcat (devname, " ", csrname, NULL);
+         (*p_WTInfoW) (WTI_CURSORS + cursorix, CSR_NAME, csrname);
+         csrname_utf8 = g_utf16_to_utf8 (csrname, -1, NULL, NULL, NULL);
+         gdkdev->info.name = g_strconcat (devname_utf8, " ", csrname_utf8, NULL);
+         g_free (csrname_utf8);
          gdkdev->info.source = GDK_SOURCE_PEN;
          gdkdev->info.mode = GDK_MODE_SCREEN;
          gdkdev->info.has_cursor = TRUE;
@@ -602,6 +613,7 @@ _gdk_input_wintab_init_check (void)
          _gdk_input_devices = g_list_append (_gdk_input_devices,
                                              gdkdev);
        }
+      g_free (devname_utf8);
     }
 }